package dcda.ctv.pricezoneapp;

import android.app.Activity;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;


public class CurrentLocation extends Activity {
	
	LocationService locationService;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test);
		
		locationService = new LocationService(CurrentLocation.this);
		
		Location nwLocation = locationService.getLocation(LocationManager.NETWORK_PROVIDER);
		
		if(nwLocation != null){
			double latitude = nwLocation.getLatitude();
			double longitude = nwLocation.getLongitude();
			
			Toast.makeText(
					getApplicationContext(),
					"Mobile Location (NetWork): \nLatitude: " + latitude
							+ "\nLongitude: " + longitude,
					Toast.LENGTH_LONG).show();		
			
			
		}else{
			Location gpsLocation = locationService.getLocation(LocationManager.GPS_PROVIDER);
			if(gpsLocation != null){
				double latitude = gpsLocation.getLatitude();
				double longitude = gpsLocation.getLongitude();
				
				Toast.makeText(
						getApplicationContext(),
						"Mobile Location (GPS): \nLatitude: " + latitude
								+ "\nLongitude: " + longitude,
						Toast.LENGTH_LONG).show();
				}else {
					
					Toast.makeText(
							getApplicationContext(),
							"We can't get your location",
							Toast.LENGTH_LONG).show(); 

					
				}			
			
		}
		
		




		
	}	
	
	
	
	
	
	
	
	
	
	
	
	/*
	LocationManager mLocationManager;
	public Location getLocation() {
        try {
            mLocationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);

            // getting GPS status
            boolean isGPSEnabled = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

            // getting network status
            boolean isNetworkEnabled = mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

            if (!isGPSEnabled && !isNetworkEnabled) {
                // no network provider is enabled
            } else {
                // First get location from Network Provider
                if (isNetworkEnabled) {
                    mLocationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER,  MIN_TIME_BW_UPDATES,  MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.d("Network", "Network");
                    if (mLocationManager != null) {
                        location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                        if (location != null) {
                            lat = location.getLatitude();
                            lng = location.getLongitude();
                        }
                    }
                }
                //get the location by gps
                if (isGPSEnabled) {
                    if (location == null) {
                        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MIN_TIME_BW_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                        Log.d("GPS Enabled", "GPS Enabled");
                        if (mLocationManager != null) {location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                            if (location != null) {
                                lat = location.getLatitude();
                                lng = location.getLongitude();
                            }
                        }
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return location;
    }
*/
	
	
	
	

}
